<?php


namespace app\controller;

use think\db\concern\Transaction;
use think\facade\Db;

class  DataTest
{

    public  function index()
    {
        //  $user =    Db::table('tp_user')->select();
        // return '111';
        $user1 =   Db::name('user')->where('id ', 76)->find();
        $user2 =  Db::table('tp_user')->where('id', 301)->find();
        $user3 = Db::table('tp_user')->where('id', 21321312)->findOrEmpty();
        // $user3 = Db::table('tp_user')->where('id',1222)->findOrFail();
        $username = Db::name('user')->where('id', 27)->value('username');
        $sql1 =  Db::getLastSql();
        $cus = Db::name('user')->column('username');

        $data=[['username'=>'辉夜1','password'=>'123',
        'gender'=>'女','email'=>'huiye@163.com','price'=>90,'details'=>'123'],
        ['username'=>'辉夜2','password'=>'123',
        'gender'=>'女','email'=>'huiye@163.com','price'=>90,'details'=>'123'],
        ['username'=>'辉夜3','password'=>'123',
        'gender'=>'女','email'=>'huiye@163.com','price'=>90,'details'=>'123'],
    
    
    ];


        // $users1 =   Db::table('tp_user')->chunk(2, function ($users) {
        //     foreach ($users as $user) {

        //         dump($user);
        //     }
        //     echo 1;
        // });
        // return  Db::name('user')->replace()->insert($data);
        // return  Db::name('user')->replace()->insertGetId($data);



        // $data=['id'=>'302','username'=>'李白2'];
        //     return Db::name('user')->exp('email','UPPER(email)')->update( $data);
        // return Db::name('user')->where('id',304)->update(['email'=>Db::raw('UPPER(email)'),
        // 'price'=>Db::raw('price+1'),'status'=>Db::raw('status-2')]);


        // return Db::name('user')->where('id',302)->delete();
        //  $user = Db::name('user')->where('id','<>',21)->select();
        //  $user = Db::name('user')->where('id','between',[19,24])->select();

        // $user =  Db::name('user')->where('create_time','>','2019-1-1')->select();
        $user =  Db::name('user')->where('create_time','not between',['2018-10-1','2019-1-1'])->select();
        
        // Db::Transaction( function ()
        // {
        //     # code...
        // });

        // Db::startTrans(function(){

        // });
        // $user =  Db::name('user')->where('email','like','%o%')->select();
        // $user = Db::name('user')->where('email','like',['xiao%','wu%'],'or')->select();;
        return json( $user->toArray());
        // return  Db::name('user')->replace()->insertAll($data);
        # code...id
    }
}
